namespace ContractAssertion
{
	using System;
	using System.Text;
	using System.Collections.Generic;
	using Microsoft.VisualStudio.TestTools.UnitTesting;
	using DependencyLib;
	using CrossFlow.GraphLib;

  /*
    Dependecy Provider:
    From .NET Assemblies
    From VS 2010 solution file
    From VS 2008 solution file
    From VS 2005 solution file
    From VS 2003 solution file
    From SQL 2005 DBs
    From XML Dependency dialec
    From XML file
  */

  [TestClass]
	public class Provider
	{
		[TestMethod]
		public void GraphCountsMocked()
		{
			IDependencyProvider provider = new MockDependencyProvider("digraph0");
			MockDependencyProvider depends = provider as MockDependencyProvider;
			depends.VertexNames.Add("v0");
			depends.VertexNames.Add("v1");
			depends.VertexNames.Add("v2");
			depends.EdgePairs.Add(new KeyValuePair<string, string>("v0", "v1"));
			depends.EdgePairs.Add(new KeyValuePair<string, string>("v0", "v2"));
			depends.EdgePairs.Add(new KeyValuePair<string, string>("v1", "v2"));
			depends.EdgePairs.Add(new KeyValuePair<string, string>("v2", "v1"));

			DirectedGraph graph = provider.CreateGraph();
			Assert.AreEqual<int>(7, graph.NodeCount);
			Assert.AreEqual<int>(4, graph.EdgeCount);
			Assert.AreEqual<int>(3, graph.VertexCount);
		}
	}

	[TestClass]
	public class TypeLevelSingleAssemblyGraph
	{
//		System.Reflection.Assembly assembly;
		MockAssemblyProvider assembly_provider = new MockAssemblyProvider();

		[TestInitialize]
		public void Setup()
		{
		}

		[TestMethod]
		public void GralCounts()
		{
			IDependencyProvider provider = new CLRDependencyProvider(assembly_provider,new List<string>());
			DirectedGraph graph = provider.CreateGraph();
			Assert.Fail("NOT ASSERTED YET");
			Assert.AreEqual<int>(7, graph.NodeCount);
			Assert.AreEqual<int>(4, graph.EdgeCount);
			Assert.AreEqual<int>(3, graph.VertexCount);
		}
	}

	[TestClass]
	public class AssemblyLevelGraph
	{
	}

	#region Mocks

	class MockAssemblyProvider : ICLRAssemblyIterator
	{
		List<System.Reflection.Assembly> assemblies;
		public MockAssemblyProvider()
		{
			assemblies = new List<System.Reflection.Assembly>();
		}
		public IEnumerable<string> NotFoundAssemblies { get { return null; } }
		public IEnumerable<System.Reflection.Assembly> GetAssemblies()
		{
			return assemblies;
		}
    public IEnumerable<System.Reflection.AssemblyName> GetAssemblyNames() { throw new NotImplementedException(); }

    public IEnumerable<System.Reflection.Assembly> GetAssemblies(bool tree) { return GetAssemblies(); }
    public System.Collections.IEnumerator GetEnumerator() { return (System.Collections.IEnumerator)GetAssemblies(); }
	}

	public class MockDependencyProvider : TemplatedBaseDependencyProvider
	{
		private string Name;
		public MockDependencyProvider(string name)
		{
			this.Name = name;
			VertexNames = new List<string>();
			VertexNamesData = new List<KeyValuePair<string, object>>();
			EdgePairs = new List<KeyValuePair<string, string>>();
			EdgeNodes = new List<EdgeInfo>();
			Subdigraphs=new List<DigraphInfo>();
		}

		public List<string> VertexNames;
		public List<KeyValuePair<string, object>> VertexNamesData;
		public List<KeyValuePair<string, string>> EdgePairs;
		public List<EdgeInfo> EdgeNodes;
		public List<DigraphInfo> Subdigraphs;

		public override TemplatedBaseDependencyProvider.DigraphInfo GetDigraphInfoFromCurrentDependencyProvider()
		{
			List<VertexInfo> vertexes=new List<VertexInfo>();
			foreach (string name in this.VertexNames)
				vertexes.Add(new VertexInfo(name));
			foreach (KeyValuePair<string, object> vertex in this.VertexNamesData)
				vertexes.Add(new VertexInfo(vertex.Key,vertex.Value));
			foreach (VertexInfo subdigraph_info in this.Subdigraphs)
				vertexes.Add(subdigraph_info);

			List<EdgeInfo> edges = new List<EdgeInfo>();
			foreach (KeyValuePair<string, string> edge in this.EdgePairs)
				edges.Add(new EdgeInfo(null, edge.Key, edge.Value, null));
			edges.AddRange(this.EdgeNodes);
			return new DigraphInfo(Name, null, vertexes, edges);
		}

        public override void Dispose(){}
	}
	#endregion
}